package com.qing.springbootdispatcherservice.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig {

	public  static final String EXCHANGE_NAME="order_fanout_exchange";

	@Bean
	public FanoutExchange fanoutExchange(){
		return new FanoutExchange(EXCHANGE_NAME,true,false);
	}

	@Bean
	public DirectExchange deadExchange(){
		return new DirectExchange("dead_exchange",true,false);
	}

	@Bean
	public Queue deadQueue(){
		return new Queue("dead.order.queue",true,false,false);
	}


	@Bean
	public Queue queue(){
		Map<String,Object> args=new HashMap<String,Object>();
		args.put("x-dead-letter-exchange","dead_exchange"); //绑定死信交换机
		args.put("x-dead-letter-routing-key","dead"); //绑定RouthKey
		args.put("x-max-length",5); //最大条数

		return new Queue("order.queue",true);
	}


	@Bean
	public Binding deadBinds(){
		return  BindingBuilder.bind(deadQueue()).to(deadExchange()).with("dead");
	}

	@Bean
	public Binding binding(){
		return BindingBuilder.bind(queue()).to(fanoutExchange());
	}
}
